package com.harr.noddles.crawler;

import com.harr.noddles.conf.AppProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CrawlerService {

    private final AppProperties appProperties;

    private Thread worker = null;

    @Autowired
    public CrawlerService(AppProperties appProperties) {
        this.appProperties = appProperties;
    }

    public CrawlerMetrics status() {
        CrawlerMetrics metricInfo = new CrawlerMetrics();
        metricInfo.setAppProperties(appProperties);
        return metricInfo;
    }

    public void start() {
        if (worker == null) {
            worker = new Thread(()->{
                while (true) {
                    Bet365Client client = new Bet365Client();
                    try {
                        String a = client.getByPD("#AC#B1#C1#D13#E36287028#F2#");
                        System.out.println(a);
                        Thread.sleep(1500);
                    } catch (InterruptedException ie) {
                        break;
                    }
                }
            });
            worker.start();
        }
    }

    public void stop() {

    }

}
